﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;
public partial class AdminManger_ModifyBook : System.Web.UI.Page
{
    SqlHelper data = new SqlHelper();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList3.DataSource = data.GetDataReader("select * from Suppliers ");
            DropDownList3.DataTextField = "SName";
            DropDownList3.DataValueField = "id";
            DropDownList3.DataBind();
            DropDownList1.DataSource = data.GetDataReader("select * from Bookstype");
            DropDownList1.DataValueField = "id";
            DropDownList1.DataTextField = "name";
            DropDownList1.DataBind();
         string   sql = "select * from Books where BooksID=" + Request.QueryString["id"].ToString();
            getdata(sql);
        }
    }
    private void getdata(string sql)
    {
        SqlDataReader dr = data.GetDataReader(sql);
        if (dr.Read())
        {
            title.Text = dr["BooksName"].ToString();
            TextBox2.Text = dr["BooksPrice"].ToString();
            TextBox3.Text = dr["BooksNum"].ToString();
            BookswholesalePrice.Text = dr["BookswholesalePrice"].ToString();
            FCKeditor1.Value = dr["BooksIntroduce"].ToString();
            pic.Text = dr["BooksPhoto"].ToString();
            Image1.ImageUrl = "../" + dr["BooksPhoto"].ToString();
            DropDownList1.Items.FindByValue(dr["BooksTypeID"].ToString()).Selected = true;
            DropDownList1.Items.FindByText(dr["BooksTypeName"].ToString()).Selected = true;
            DropDownList3.Items.FindByText(dr["Suppliers"].ToString()).Selected = true;
            if (Convert.ToString(dr["BooksSpecial"]).Trim() == "否")
            {
                DropDownList2.SelectedIndex = 0;
            }
            if (Convert.ToString(dr["BooksSpecial"]).Trim() == "是")
            {
                DropDownList2.SelectedIndex = 1;
            }

        }

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string res;
        upload up = new upload();
        res = up.Up(file1, "../uploadfiles/");
        this.Label1.Visible = true;
        this.Label1.Text = up.Resup[Convert.ToInt32(res)];
        this.pic.Text = up.s;
        Image1.ImageUrl = "../" + pic.Text;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string sql = "update Books set BooksName='" + title.Text.ToString().Trim() + "',BooksPrice='" + TextBox2.Text + "',BooksNum='" + TextBox3.Text + "',BooksIntroduce='" + FCKeditor1.Value + "' ,BooksPhoto='" + pic.Text + "',BooksTypeID='" + DropDownList1.SelectedValue + "',BooksTypeName='" + DropDownList1.SelectedItem.Text + "' ,BooksSpecial='" + DropDownList2.SelectedValue + "',BookswholesalePrice='" + BookswholesalePrice.Text + "',BooksCostPrice='" + BookswholesalePrice.Text + "'  where BooksID=" + Request.QueryString["id"].ToString();
        data.RunSql(sql);
        Alert.AlertAndRedirect("修改成功", "BooksManger.aspx");
    }
}
